@model UpdaterManagement.Models.DeployedApplication

<nav aria-label="breadcrumb" class="breadcrumb-ace">
    <ol class="breadcrumb">
        <li class="breadcrumb-item"><a href="/">首页</a></li>
        <li class="breadcrumb-item"><a href="/DeployedApplication">已部署应用</a></li>
        <li class="breadcrumb-item active">编辑应用</li>
    </ol>
</nav>

<div class="page-header">
    <div class="d-flex justify-content-between align-items-center">
        <div>
            <h1 class="page-title">
                <i class="bi bi-pencil text-primary me-2"></i>编辑已部署应用
            </h1>
            <p class="page-subtitle">修改应用 <strong>@Model.ServiceName</strong> 的信息</p>
        </div>
        <a href="/DeployedApplication" class="btn btn-outline-secondary">
            <i class="bi bi-arrow-left me-2"></i>返回列表
        </a>
    </div>
</div>

<div class="row">
    <div class="col-lg-8">
        <div class="card-ace">
            <div class="card-header">
                <i class="bi bi-form-check me-2"></i>应用信息
            </div>
            <div class="card-body">
                <partial name="_ErrorAlert" />
                
                <form method="post">
                    <input type="hidden" asp-for="Id" />
                    <input type="hidden" asp-for="CreatedTime" />
                    
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label-ace">
                                    <i class="bi bi-gear text-primary me-1"></i>服务名称
                                </label>
                                <input type="text" class="form-control form-control-ace" asp-for="ServiceName" required />
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label-ace">
                                    <i class="bi bi-tag text-primary me-1"></i>服务版本
                                </label>
                                <input type="text" class="form-control form-control-ace" asp-for="ServiceVersion" required />
                            </div>
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label-ace">
                                    <i class="bi bi-hdd-network text-primary me-1"></i>服务器IP
                                </label>
                                <input type="text" class="form-control form-control-ace" asp-for="ServerIp" required />
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label-ace">
                                    <i class="bi bi-box-seam text-primary me-1"></i>所属产品
                                </label>
                                <select class="form-select form-control-ace" asp-for="ProductId" required>
                                    <option value="">请选择产品</option>
                                    @foreach (var product in ViewBag.Products as List<UpdaterManagement.Models.Product>)
                                    {
                                        <option value="@product.Id" selected="@(product.Id == Model.ProductId)">@product.Name</option>
                                    }
                                </select>
                            </div>
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label-ace">
                                    <i class="bi bi-building text-primary me-1"></i>企业名称
                                </label>
                                <select class="form-select form-control-ace" asp-for="EnterpriseId" id="enterpriseSelect" required>
                                    <option value="">请选择企业</option>
                                    @foreach (var enterprise in ViewBag.Enterprises as List<UpdaterManagement.Models.Enterprise>)
                                    {
                                        <option value="@enterprise.Id" data-code="@enterprise.Code" selected="@(enterprise.Id == Model.EnterpriseId)">@enterprise.Name</option>
                                    }
                                </select>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label-ace">
                                    <i class="bi bi-hash text-primary me-1"></i>企业编号
                                </label>
                                <input type="text" class="form-control form-control-ace" id="enterpriseCode" readonly style="background-color: #f8f9fa;" />
                            </div>
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label-ace">
                                    <i class="bi bi-folder text-primary me-1"></i>部署路径
                                </label>
                                <input type="text" class="form-control form-control-ace" asp-for="DeployPath" required />
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label-ace">
                                    <i class="bi bi-pc-display text-primary me-1"></i>系统类型
                                </label>
                                <select class="form-select form-control-ace" asp-for="SystemType" required>
                                    <option value="Windows">Windows</option>
                                    <option value="Linux">Linux</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    
                    <div class="mb-3">
                        <label class="form-label-ace">
                            <i class="bi bi-chat-text text-primary me-1"></i>应用描述
                        </label>
                        <textarea class="form-control form-control-ace" asp-for="Description" rows="3"></textarea>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label-ace">
                                    <i class="bi bi-activity text-primary me-1"></i>运行状态
                                </label>
                                <select class="form-select form-control-ace" asp-for="Status">
                                    <option value="Running">运行中</option>
                                    <option value="Stopped">已停止</option>
                                    <option value="Error">错误</option>
                                    <option value="Maintenance">维护中</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3 d-flex align-items-end">
                                <div class="form-check">
                                    <input type="checkbox" class="form-check-input" asp-for="IsActive" />
                                    <label class="form-check-label">
                                        <i class="bi bi-toggle-on text-success me-1"></i>启用应用
                                    </label>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="d-flex gap-2 pt-3 border-top">
                        <button type="submit" class="btn btn-ace-primary">
                            <i class="bi bi-check-circle me-2"></i>保存修改
                        </button>
                        <a href="/DeployedApplication" class="btn btn-outline-secondary">
                            <i class="bi bi-x-circle me-2"></i>取消
                        </a>
                    </div>
                </form>
            </div>
        </div>
    </div>
    
    <div class="col-lg-4">
        <div class="card-ace">
            <div class="card-header">
                <i class="bi bi-clock text-info me-2"></i>应用信息
            </div>
            <div class="card-body">
                <div class="mb-3">
                    <strong class="text-muted">创建时间:</strong>
                    <br>@Model.CreatedTime.ToString("yyyy-MM-dd HH:mm:ss")
                </div>
                <div class="mb-3">
                    <strong class="text-muted">最后更新:</strong>
                    <br>@Model.LastUpdated.ToString("yyyy-MM-dd HH:mm:ss")
                </div>
                <div class="mb-0">
                    <strong class="text-muted">当前状态:</strong>
                    <br>
                    @if (Model.Status == "Running")
                    {
                        <span class="badge badge-ace-success">运行中</span>
                    }
                    else if (Model.Status == "Stopped")
                    {
                        <span class="badge badge-ace-danger">已停止</span>
                    }
                    else
                    {
                        <span class="badge badge-ace-warning">@Model.Status</span>
                    }
                </div>
            </div>
        </div>
    </div>
</div>

<script>
// 初始化企业编号
const enterpriseSelect = document.getElementById('enterpriseSelect');
const selectedOption = enterpriseSelect.options[enterpriseSelect.selectedIndex];
if (selectedOption && selectedOption.dataset.code) {
    document.getElementById('enterpriseCode').value = selectedOption.dataset.code;
}

// 企业选择变化时自动填充企业编号
enterpriseSelect.addEventListener('change', function() {
    const selectedOption = this.options[this.selectedIndex];
    const enterpriseCode = selectedOption.dataset.code || '';
    document.getElementById('enterpriseCode').value = enterpriseCode;
});
</script>